<%@page import="com.shsh.safemanage.model.Department3"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="com.shsh.safemanage.dao.RoleDao"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<%
{
String selectedBy = request.getParameter(Constants.REQUEST_PARAMETER_SELECTED_BY);
	
Long selectedID = 0L;


RoleDao roleDao = DaoCreator.createRoleDao();

if(selectedBy == null){
	//selecte by role id with default.
	String roleIDStr = request.getParameter(Constants.REQUEST_PARAMETER_ROLE_ID);
	try{
		selectedID = Long.parseLong(roleIDStr);
	}catch(Exception e){	
	}
} else if(selectedBy.equals(Constants.CONST_SELECTED_BY_DEPART3ID)) {
	String depart3IDStr = request.getParameter(Constants.REQUEST_PARAMETER_DEPARTMENT3ID);
	Long depart3ID = 0L;
	try {
		depart3ID = new Long(depart3IDStr);
	} catch (Exception e) {
	}

	DepartmentDao departDao = DaoCreator.createDepartmentDao();
	
	Department3 depart3 = departDao.getDepartment3ByID(depart3ID);
	if(depart3!=null){
		selectedID = depart3.getRoleID();	
	}	
} else if(selectedBy.equals(Constants.CONST_SELECTED_BY_JOBPOSTID)) {
	String jobPostIDStr = request.getParameter(Constants.REQUEST_PARAMETER_JOB_POST_ID);
	Long jobPostID = 0L;
	try {
		jobPostID = new Long(jobPostIDStr);
	} catch (Exception e) {
	}

	TitlePostManageGroupDao departDao = DaoCreator.createTitlePostManageGroupDao();
	
	JobPost jobPost = departDao.getJobPostByID(jobPostID);
	if(jobPost!=null){
		selectedID = jobPost.getRoleID();	
	}	
}

List<Role> roleList = roleDao.getRoleList();

%>
<select id="role">
<%
for (Role role: roleList) {
%>
	<option value="<%=role.getId()%>" <%=role.getId().equals(selectedID)? "selected":""%> ><%=role.getRoleName()%></option>
<%
}
%>
</select>
<%
}
%>
